<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>ref</title>
</head>
<body>
  <div id="app">
    <!-- 元素 -->
    <button ref="btn" id="mybtn">按钮</button>
    <my-root></my-root>
  </div>
</body>
<template id="root">
  <div :style="{width: '100%',height: '500px','background-color': bgColor}">
    <!-- 组件 -->
    <my-box ref="mybox"></my-box>
  </div>
</template>
<template id="box">
  <div :style="{ width: '300px', height: '300px', 'background-color': '#ccc'}">
    <input type="color" v-model="color">
  </div>
</template>
<script src="../lib/vue.global.js"></script>
<script>
  const Box = {
    template: '#box',
    data () {
      return {
        color: '#0f0'
      }
    },
    methods: {
      test () {
        console.log('测试')
      }
    }
  }

  const Root = {
    template: '#root',
    data () {
      return {
        bgColor: '#f66'
      }
    },
    mounted () {
      console.log(this.$refs.mybox)
      this.bgColor = this.$refs.mybox.color
      this.$refs.mybox.test()
    },
    components: {
      MyBox: Box
    }
  }
  const app = Vue.createApp({
    components: {
      MyRoot: Root
    },
    mounted () {
      console.log(this.$refs.btn)
      console.log(document.getElementById('mybtn'))
      console.log(document.getElementById('mybtn') === this.$refs.btn)
    }
  })

  app.mount('#app')
</script>
</html>